package edu.gatech.mobile.scene.model;

import java.util.List;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;

import edu.gatech.mobile.scene.image.util.HistogramCompareUtil;

/**
 * color histogram object for a given image patch. 
 * @author Jing
 *
 */

public class ColorHistogram {
	//List of histograms one for each channel.
	List<Mat> colorHistogram;
	
	//the patch id associated with the histogram
	long maskId;
	
	
	long timePosted;
	
	public ColorHistogram(){
		
	}
	
	/**
	 * 
	 * @param maskId
	 * @param colorHistogram
	 */
	public ColorHistogram(long maskId, List<Mat> colorHistogram){
		this.maskId = maskId;
		this.colorHistogram = colorHistogram;
	}
	/**
	 * 
	 * @param colorHistogram
	 */
	public ColorHistogram(List<Mat> colorHistogram){
		this.colorHistogram = colorHistogram;
	}

	
	/**
	 * normalize the color histogram.
	 */
	public void normalizeColorHistogram() {
		for(int i=0; i<this.colorHistogram.size(); i++){
			Mat hist = this.colorHistogram.get(i);
			Scalar sumScalar = Core.sumElems(hist);
			double sum = sumScalar.val[0];
			Mat normalizer = HistogramCompareUtil.getNormalizer(
					hist.height(), hist.width(), sum, hist.type());
			Mat normalizedHist = new Mat(hist.height(), hist.width(),
					hist.type());
			Core.divide(hist, normalizer, normalizedHist);
			this.colorHistogram.set(i, normalizedHist);
			hist.release();
			normalizer.release();
		} 
	}
	
	
	public List<Mat> getColorHistogram() {
		return colorHistogram;
	}

	public void setColorHistogram(List<Mat> colorHistogram) {
		this.colorHistogram = colorHistogram;
	}

	public Long getMaskId() {
		return maskId;
	}

	public void setMaskId(long maskId) {
		this.maskId = maskId;
	}

	public Long getTime() {
		return timePosted;
	}

	public void setTime(long timePosted) {
		this.timePosted = timePosted;
	}
	
}
